package top.pcat;

import lombok.extern.slf4j.Slf4j;
import top.pcat.server.GateWayServer;
import top.pcat.util.ZookeeperListener;
import top.pcat.util.RotationLoadBalancer;

import java.util.concurrent.CopyOnWriteArrayList;

@Slf4j
public class GateWayMain {


    public static CopyOnWriteArrayList<String> strings = new CopyOnWriteArrayList<String>();

    public static RotationLoadBalancer loadBalancer = new RotationLoadBalancer();

    public static void main(String[] args) {
        log.info("启动网关");

        Thread t = new Thread(new Runnable(){
            @Override
            public void run() {
                try {
                    log.info("启动网关");
                    ZookeeperListener zookeeperGan = new ZookeeperListener();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });

        t.start();

        //启动netty服务器
        GateWayServer gateWayServer = new GateWayServer();

        try {
            gateWayServer.init();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        // 负载均衡类
        RotationLoadBalancer loadBalancer = new RotationLoadBalancer();

        //获取地址
        loadBalancer.getAddress(strings);

    }

    public static String getAddress() {
        String address = loadBalancer.getAddress(strings);
        log.info("获取ip"+address);
        return address;
    }

}